﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using IndexMarkSilverlightClient.IndexMarkServiceReference;
using IndexMarkSilverlightClient.Views.Controls;
using SharedCode.Controls;
using IndexMarkSilverlightClient.Views.Controls.ReportsControls;

namespace IndexMarkSilverlightClient.Views
{
    public partial class ReportsMain : Page
    {
        MainViewModel viewModel = null;
       
        const string sPPS = "ППС", sDoctor = "Доктора наук", sEmployee = "Сотрудники", sCollege = "Колледж";
        Dictionary<object, IndexStrategyType> types = 
            new Dictionary<object, IndexStrategyType>() { 
                {sPPS, IndexStrategyType.PPS}, 
                {sDoctor, IndexStrategyType.Doctor},
                //{sEmployee, IndexStrategyType.Employee}, 
                //{sCollege, IndexStrategyType.College}, 
        };
        IndexStrategyType SelectedType
        {
            get
            {
                return _ReportType.SelectedItem == null ? 
                    IndexStrategyType.PPS : types[_ReportType.SelectedItem];
            }
        }

        public ReportsMain()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(ReportsMain_Loaded);
            _ReportType.ItemsSource = types.Keys;
            _ReportType.SelectedIndex = 0;
        }

        void ReportsMain_Loaded(object sender, RoutedEventArgs e)
        {
            //bool IsSupervisor = (((((this as ReportsMain).Parent as Frame).Parent as Border).Parent as Grid).Parent as MainPage).ViewModel.User.IsSupervisor;
            if (!MainPage.ViewModel.IsSuperivsor)
            {
                PremiumsItem.Visibility = System.Windows.Visibility.Collapsed;
                //IndexDocs.Visibility = System.Windows.Visibility.Collapsed;
            }
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {

        }

        private void TreeViewItem_Selected(object sender, RoutedEventArgs e)
        {
            Content.Children.Clear();
            Content.Children.Add(new IndexMarkSilverlightClient.Views.Controls.VolumsPPS());//SelectedType
        }

        private void TreeViewItem_Selected_2(object sender, RoutedEventArgs e)
        {
            Content.Children.Clear();
            Content.Children.Add(new NullableCharacteristic());
        }

        private void TreeViewItem_Selected_3(object sender, RoutedEventArgs e)
        {
            Content.Children.Clear();
            Content.Children.Add(new AvgIndexes(SelectedType));
        }

        private void TreeViewItem_Selected_4(object sender, RoutedEventArgs e)
        {
            Content.Children.Clear();
            Content.Children.Add(new LIDIA());
        }

        public static void ShowLidia(IndexRow IR, int trm)
        {
            var cv = new ChildWindow();
            cv.Content = new LIDIA(IR, trm);
            cv.Show();
        }

        public void NavigateToLIDIA(IndexRow IR, int trm)
        {
            //try
            //{
            //    ((ReportsTreeView.Items[1] as TreeViewItem).Items[1] as TreeViewItem).IsSelected = true;
            //}
            //catch { }
            Content.Children.Clear();
            Content.Children.Add(new LIDIA(IR, trm));
        }

        private void TreeViewItem_Selected_5(object sender, RoutedEventArgs e)
        {
            Content.Children.Clear();
            Content.Children.Add(new DistibutionIndexes(SelectedType));
        }

        private void Money_Selected(object sender, RoutedEventArgs e)
        {
            Content.Children.Clear();
            Content.Children.Add(new Nadbavki(SelectedType));
        }

        private void Index_Selected(object sender, RoutedEventArgs e)
        {
            Content.Children.Clear();
            Content.Children.Add(new IndexList());
        }

        private void Index_Docs(object sender, RoutedEventArgs e)
        {
            Content.Children.Clear();
            Content.Children.Add(new IndexListDoc());
        }
    }
}
